<?php
namespace app\share\controller;

use app\share\model\SendSms;
use think\Validate;

class SendCode
{
    public function __construct()
    {
        $this->send_code = new SendSms();
    }
    /**
     * 发送短信
     * @param string  $mobile 手机号码
     * @return string
     */
    public function sendCode()
    {
        $input = input();
        $validate = new Validate([
            ['mobile', 'require|max:11|/^1[3-8]{1}[0-9]{9}$/', '手机号码不能为空|手机号码不能超过11个字符|手机号码格式不正确'],
        ]);
        $code = mt_rand(10000,99999);
        if(!$validate->check($input))
        {
            return ['code'=>-1001,'msg'=>$validate->getError()];
        }
        return $this->send_code->sendSms($input['mobile'], $code);
    }

}